<?php

namespace app\admin\model;

use think\Model;
use think\model\concern\SoftDelete;

class PohtoList extends Model
{
    use SoftDelete;
    protected $name = 'car_photo_list'; //表名
    protected $autoWriteTimestamp = true;
    // 定义时间戳字段名
    protected $dateFormat = 'Y/m/d H:i:s';
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';
    protected $deleteTime='delete_at';
    public function tabInfo()
    {
        return $this->hasOne(PohtoType::class, 'id', 'type_id');
    }

    public function tanName()
    {
        return $this->hasOne(PohtoType::class, 'id', 'type_id')->bind(['tabName' => 'name']);
    }

    public function userInfo() {
        return $this->hasOne(PohtoUser::class, 'id', 'author_id')->with(['institutionName'])->bind([
            'institution_name',
            'institution_id',
            'author_name' => 'username'
        ]);
    }

    public function buy() {
        return $this->hasOne(PhotoBuy::class, 'photo_id', 'id');
    }

    public function report() {
        return $this->hasOne(PohtoReport::class, 'photo_id', 'id');
    }

    public function setTagsAttr($value)
    {
        if($value) {
            return implode(",",$value);
        }
        return null;
    }

    public function getTagsAttr($value)
    {
        if($value) {
            return explode(',',$value);
        }
        return [];
    }
}